import { reactive, ref } from 'vue';
import { cloneDeep } from 'lodash-es';
//列表数据hook
export const uselist = (
  typeData: any, //列表数据
  pageInit?: any, //页码初始化数据
  search?: any //搜索数据
) => {
  const lockDialog = ref(false);
  const initialPagination = ref(cloneDeep(pageInit));
  const searchForm = reactive(search);
  const tableOptions = reactive({
    tableLoading: false,
    ...typeData,
  });
  //获取列表
  const getList = async (listUrl: any) => {
    lockDialog.value = false;
    tableOptions.tableLoading = true;
    const body = cloneDeep(Object.assign(initialPagination.value, searchForm));
    const res: any = await listUrl(body);
    tableOptions.tableLoading = false;
    tableOptions.columnDatas = res.data.data;
    initialPagination.value.rowsNumber = res.data.total;
  };
  return {
    lockDialog,
    initialPagination,
    searchForm,
    tableOptions,
    getList,
  };
};
